<?php if ( ! defined('WDK_PATH')) exit('No direct script access allowed');?>
<link rel="stylesheet" type="text/css" href="/js/jquery/loadmask/jquery.loadmask.css" />
<script src="/js/jquery/loadmask/jquery.loadmask.min.js"></script>
<iframe id="wdUploadFrame" width="500" height="300" frameborder="1" name="wdUploadFrame"></iframe>
<form id="wdUuploadForm" action="http://{config.file}/plugin/uploader/upload.php" method="POST" enctype="multipart/form-data" target="wdUploadFrame">
<input type="hidden" name="time" value="{time}"/>
<input type="hidden" name="host" value="{host}"/>
<input type="hidden" name="code" value="{code}"/>
<input type="hidden" name="sign" value="{sign}"/>
<input type="file" name="file" style="visibility:hidden;"/>
</form>
<script>
(function($){
	$.fn.wduploader = function() {
		return this.each(function(){
			var $self = $(this);
			var tag = [];
			tag.push('<div class="uploadFiles"></div>');
			tag.push('<div><input type="text" size="50" readonly="readonly"/><a class="btn wdupload"> 업로드</a></div>');
			$self.html(tag.join(''));
			$self.find('a.wdupload').prev().click(function(){
				$('#wdUuploadForm>:file').data('target', $(this));
				$('#wdUuploadForm>:file').click();
			});
			$self.find('a.wdupload').click(function(){
				if($(this).prev().val() == ''){return alert('첨부된 파일이 없습니다.');}
				$('body').mask('파일을 업로드중입니다...');
				$('#wdUuploadForm').submit();
			});
		});
		return this;
	};
	$('#wdUuploadForm>:file').change(function(){
		$('#wdUuploadForm>:file').data('target').val($(this).val());
	});
	$('div.wduploader').wduploader();
})(jQuery);
function wdUploadComplete(json)
{
	var tag = [];
	tag.push('<div>');
	tag.push('<input type="hidden" name="filename[]" value="'+json.name+'"/>');
	tag.push('<input type="hidden" name="fileurl[]" value="'+json.url+'"/>');
	tag.push(json.name);
	tag.push('</div>');
	$('.uploadFiles').append(tag.join(''));
	$('.nicedit').data('niceditor').setContent($('.nicedit').data('niceditor').getContent() + '<img src="'+json.url+'"/>')
	$('body').unmask();
}
</script>